package com.wd.health.model.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.wd.health.R;

import java.util.List;

/**
 * @ProjectName:shopmall
 * @Package:com.bawei.emojidemo
 * @ClassName:RvAdapter
 * @UpdateUser: 裴童童
 * @date: 2021/1/6
 */
public class EmojiAdapter extends RecyclerView.Adapter<EmojiAdapter.ViewHolder>{
    private List<String> emojis;
    private Context context;

    public EmojiAdapter(List<String> emojis, Context context) {
        this.emojis = emojis;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(View.inflate(context, R.layout.item_emoji,null));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.tv.setText(emojis.get(position));
        holder.tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String s = emojis.get(position);
                getListener.onClick(s);
                notifyDataSetChanged();
            }
        });
    }

    @Override
    public int getItemCount() {
        return emojis.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private final TextView tv;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.tv);
        }
    }

    //接口回调
    public interface GetListener {
        void onClick(String emoji);
    }

    private GetListener getListener;

    public void setGetListener(GetListener getListener) {
        this.getListener = getListener;
    }
    private  int mPosition;

    public int getmPosition() {
        return mPosition;
    }

    public void setmPosition(int mPosition) {
        this.mPosition = mPosition;
    }
} 
